package cn.cyh.order.controller;

import cn.cyh.basic.uitls.AJaxResult;
import cn.cyh.basic.uitls.LoginContext;
import cn.cyh.basic.uitls.PageList;
import cn.cyh.order.domain.ProductOrder;
import cn.cyh.order.query.ProductOrderQuery;
import cn.cyh.order.service.IProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/productOrder")
public class ProductOrderController {

    @Autowired
    private IProductOrderService productOrderService;
    @PostMapping("/submit")
    public AJaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try {
            String payData = productOrderService.submit(params, LoginContext.currentLongInfo(request));
            return AJaxResult.myself().setResultObj(payData);
        } catch (Exception e) {
            e.printStackTrace();
            return AJaxResult.myself().setMsg(e.getMessage()+"下单失败");
        }

    }
    /**
     * 管理端查询领养订单接口
     * @param query
     * @param request
     * @return
     */
    @PostMapping("/admin")
    public PageList<ProductOrder> admin(@RequestBody ProductOrderQuery query, HttpServletRequest request){
        return productOrderService.admin(query,LoginContext.currentLongInfo(request));
    }
}
